package at.fhooe.im440.pandora.graphic;

import java.awt.Graphics2D;

import at.fhooe.im440.pandora.visuals.Rect;
import at.fhooe.im440.pandora.visuals.Visual;

public class Ship extends GameGraphic {

	private String dir;
	

	private float x;
	private float y;
	private int h;
	private int w;
	private double rot;
	
	public Ship(float x, float y, int w, int h){
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;	
		
		this.dir = "";
		
		this.addVisual(new Rect());
		
	}


	public void draw(Graphics2D g){
		
		applyRotation(g);
		updateVisuals();
		
		for (Visual v : this.visuals) {
			v.draw(g);
		}
		
		
		g.drawRect((int) x, (int) y, w, h);
	}

	protected void updateVisuals(){
		for (Visual v : this.visuals) {
			v.update();
		}
	}
	
	private void applyRotation(Graphics2D g) {
		//move this to Rect class?	
		g.rotate(rot, x+(w/2), y+(h/2));
	}
	
	public void setDir(String dir) {
		this.dir = dir;
		if(dir == "DOWN") {
			y -= 10;
		} else if(dir == "UP") {
			y += 10;
		} else if(dir == "RIGHT") {
			x += 10;
		} else if(dir == "LEFT") {
			x -= 10;
		} else if(dir == "ROTATE_LEFT") {
			rot += Math.toRadians(5);
		} else if(dir == "ROTATE_RIGHT") {
			rot -= Math.toRadians(5);
		} 
	}
	
	public float getX() {
		return x;
	}

	public float getY() {
		return y;
	}
}
